package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Sidedishmenu;
import com.restaurant.service.SidedishmenuService;

public class SidedishmenuServiceImpl implements SidedishmenuService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Sidedishmenu addOrModify( Sidedishmenu objSidedishmenu ) {
       return ( Sidedishmenu ) hibernateTemplate.merge( objSidedishmenu );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Sidedishmenu deleteRecord( Sidedishmenu objSidedishmenu ) {
       hibernateTemplate.delete( objSidedishmenu );
       return objSidedishmenu;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Sidedishmenu modifyRecord( Sidedishmenu objSidedishmenu ) {
       return ( Sidedishmenu ) hibernateTemplate.merge( objSidedishmenu );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Sidedishmenu> loadAll() {
       return (List<Sidedishmenu>)hibernateTemplate.findByNamedQuery( "Sidedishmenu.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Sidedishmenu loadByPrimaryKey( Long primaryKey ) {
       return (Sidedishmenu) hibernateTemplate.get( Sidedishmenu.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Sidedishmenu deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Sidedishmenu> loadByHql(String query) {
       return ( List<Sidedishmenu> ) hibernateTemplate.find( query );
   }
}